package basics;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

import utils.Converter;

public class FeaturesSet extends ArrayList<VectorMatrix> {

	public void read(String filePath) {
		read(filePath, ",");
	}

	public void read(String filePath, String seperator) {
		try {
			this.clear();
			BufferedReader br = new BufferedReader(new FileReader(filePath));
			String line;
			while ((line = br.readLine()) != null) {
				String[] s = line.split(seperator);
				Vector v = new DenseVector(Converter.parseToDouble(s));
				this.add(v);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public double max() {
		return max(VectorMatrixUtils.OperationOpt.Default);
	}

	public double max(VectorMatrixUtils.OperationOpt opt) {
		double max = Double.MIN_VALUE;
		for (VectorMatrix vm : this) {
			double t = VectorMatrixUtils.max(vm, opt);
			if (t > max) {
				max = t;
			}
		}
		return max;
	}

	public double min() {
		return min(VectorMatrixUtils.OperationOpt.Default);
	}

	public double min(VectorMatrixUtils.OperationOpt opt) {
		double min = Double.MAX_VALUE;
		for (VectorMatrix vm : this) {
			double t = VectorMatrixUtils.min(vm, opt);
			if (t < min) {
				min = t;
			}
		}
		return min;
	}
}
